<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v-on="http://www.w3.org/1999/xhtml"
      xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>

    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <meta http-equiv="pragma" content="no-cache" />
    <meta http-equiv="expires" content="Wed, 26 Feb 1997 08:21:57 GMT"/>
    <title>购买订单</title>
    <link rel="stylesheet" href="../css/bootstrap.min.css">
    <link rel="stylesheet" href="../css/common.css">
    <link rel="stylesheet" href="../css/nav.css">
    <link rel="stylesheet" href="../css/font-awesome.css">
    <link rel="stylesheet" href="../css/element/index.css">
	<link rel="stylesheet" href="../css/hsg.css">

   
</head>
<body>
<div id="wrapper" v-cloak>
    <div >
        <div style="padding: 0 20px">
            <div>
                <div style="color: #666; font-weight: bold; border-bottom: 1px solid #ccc; padding: 10px 0; margin-bottom: 20px; font-size: 30px;">购买订单添加</div>
            </div>
            <div style="margin-top: 10px">
                <div style="border: 1px solid #19a97b;">
                    <div style="padding: 5px; border-bottom: 1px solid #19a97b; color: white; background-color: #19a97b;">购买订单添加</div>
                    <br>
           
            <form class="form-horizontal">
                <input type="hidden" id="id" name="id" v-model="entity.id">
               <div  class="form-group"><label class="col-sm-3 control-label">商品编号</label><div class="col-sm-7"><input type="text" class="form-control" v-model="entity.goodsnumbers" style="width: 160px" placeholder="请输入商品编号" id="goodsnumbers" disabled ></div></div>
		<div  class="form-group"><label class="col-sm-3 control-label">商品名称</label><div class="col-sm-7"><input type="text" class="form-control" v-model="entity.goodsnamec" style="width: 160px" placeholder="请输入商品名称" id="goodsnamec" disabled ></div></div>
		<div  class="form-group"><label class="col-sm-3 control-label">类别</label><div class="col-sm-7"><input type="text" class="form-control" v-model="entity.types" style="width: 160px" placeholder="请输入类别" id="types" disabled ></div></div>
		<div  class="form-group"><label class="col-sm-3 control-label">价格</label><div class="col-sm-7"><input type="text" class="form-control" v-model="entity.price" style="width: 160px" placeholder="请输入价格" id="price" @input="hsgjisuan()" disabled ></div></div>
		<div  class="form-group"><label class="col-sm-3 control-label">购买数量</label><div class="col-sm-7"><input type="text" class="form-control" v-model="entity.goumaicounts" style="width: 160px" placeholder="请输入购买数量" id="goumaicounts" @input="hsgjisuan()" ></div></div>
		<div  class="form-group"><label class="col-sm-3 control-label">购买金额</label><div class="col-sm-7"><input type="text" class="form-control" v-model="entity.goumaiamount" style="width: 160px" placeholder="此项不必填写，系统自动计算" id="goumaiamount" disabled></div></div>
		<div  class="form-group"><label class="col-sm-3 control-label">账号</label><div class="col-sm-7"><input type="text" class="form-control" v-model="entity.username" style="width: 160px" placeholder="请输入账号" id="username" disabled></div></div>
		<div  class="form-group"><label class="col-sm-3 control-label">姓名</label><div class="col-sm-7"><input type="text" class="form-control" v-model="entity.names" style="width: 160px" placeholder="请输入姓名" id="names"></div></div>
		<div  class="form-group"><label class="col-sm-3 control-label">余额</label><div class="col-sm-7"><input type="text" class="form-control" v-model="entity.yue" style="width: 160px" placeholder="请输入余额" id="yue"></div></div>
		<div  class="form-group"><label class="col-sm-3 control-label">收货电话</label><div class="col-sm-7"><input type="text" class="form-control" v-model="entity.takedeliverytel" style="width: 160px" placeholder="请输入收货电话" id="takedeliverytel"></div></div>
		<div  class="form-group"><label class="col-sm-3 control-label">收货地址</label><div class="col-sm-7"><input type="text" class="form-control" v-model="entity.takedeliveryaddress" style="width: 160px" placeholder="请输入收货地址" id="takedeliveryaddress"></div></div>
		
            </form>

            <div class="modal-footer">
                <button type="button" class="btn btn-primary" @click="update">保存</button>
            </div>
        </div>
        </div>
        </div>
    </div>

</div>


<script src="../js/jquery-1.10.2.js"></script>
<script src="../js/bootstrap.min.js"></script>
<script src="../js/nav.js"></script>
<script src="../js/my.js"></script>
<script src="../js/vue2.6.11/vue.min.js"></script>
<script src="../js/vue2.6.11/axios.js"></script>
<script src="../js/element/index.js"></script>

<script>
    function checkValid(entity) {
       
        if (entity.goumaicounts && entity.goumaicounts !== ""){let reg = /^[0-9]+.?[0-9]*$/; if (!reg.test(entity.goumaicounts)) {alert("购买数量必需数字型");return false;}}
if (entity.takedeliverytel && entity.takedeliverytel !== ""){let reg = /^[1][3,4,5,7,8][0-9]{9}$/; if (!reg.test(entity.takedeliverytel)) {alert("请输入正确的收货电话");return false;}}
if (parseInt(entity.goumaiamount) > parseInt(entity.yue)) {alert("对不起，余额必需大于购买金额");return false;}
        return true;
    }
   
    new Vue({
        el: '#wrapper',
        data: {
            goumaiordersid: 0,
           //hsgdanhejisuan
            goumaiordersInfo: {},
            isShow: false,
            user: {},
            entity:{
            },
        },
        created: function () {
            axios.get('/auth').then(res => {
                if (res.data.code === '0') {
                    this.user = res.data.data;
                }
            });
            this.goodsinfosid = this.getQueryVariable('goodsinfosid');
            this.loadGoumaiordersInfo();
			this.user = JSON.parse(localStorage.getItem('user'));
			if (this.user.level === "注册用户"){this.entity.username = this.user.username;}
        },
        methods: {
            loadGoumaiordersInfo() {
                axios.get("/goodsinfosInfo/" + this.goodsinfosid).then(res => {
                    if (res.data.code === '0') {
                        const goodsinfos = res.data.data;
                        this.entity = {goodsnumbers:goodsinfos.goodsnumbers,goodsnamec:goodsinfos.goodsnamec,types:goodsinfos.types,price:goodsinfos.price}
						if (this.user.level === "注册用户"){this.entity.username = this.user.username;}
						//tupianloadtb
						//dhjsuanxx
                    } else {
                        alert(res.data.msg);
                    }
                });
            },
			getQueryVariable(variable) {
                let query = window.location.search.substring(1);
                let vars = query.split("&");
                for (let i = 0; i < vars.length; i++) {
                    let pair = vars[i].split("=");
                    if (pair[0] === variable) {
                        return pair[1];
                    }
                }
                return '';
            },
			hsgjisuan(){
                this.entity.goumaiamount = 1*Number(this.entity.price)*Number(this.entity.goumaicounts);
            },
           
			
			//m_liangbuinit
			
			update() {
                if (checkValid(this.entity)) {
                    axios.post(
                        "/goumaiordersInfo", this.entity
                    ).then(res => {
                        if (res.data.code === '0') {
                            msg('success', '添加成功');
                        } else {
                            msg('error', res.data.msg);
                        }
                    })
                }
            },
			//m_tupiansccsbaul
           
            downModel() {
                location.href = '/goumaiordersInfo/getExcelModel';
            },
            clickUpload: function (e) {
                if (this.user.level === "管理员")
                {}
                else
                {
                    msg('warning', '你没有权限操作');
                    return;
                }
            },
            upload: function () {
                let files = this.$refs.file.files;
                for (let i = 0; i < files.length; i++) {
                    let formData = new FormData();
                    formData.append('file', files[i]);
                    axios.post('/goumaiordersInfo/upload', formData, {
                        'Content-Type': 'multipart/form-data'
                    }).then(res => {
                        if (res.data.code === '0') {
                            msg('success', '批量导入成功');
                            this.loadTable(1);
                        } else {
                            msg('error', res.data.msg);
                        }
                    })
                }
            },
			
			//youscwenjian
            
			//x2suilafuxzhi
           
        }
    })
</script>
</body>
</html>
